<% layout('/layouts/default.html', {title: '客户管理', libs: ['validate','fileupload','dataGrid']}){ %>

<script src="${ctxStatic}/modules/pinyin/Convert_Pinyin.js"></script>

<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(customer.isNewRecord ? '新增客户' : '编辑客户')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${customer}" action="${ctx}/base/customer/customer/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
                <#form:hidden path="treeSort" class="form-control"/>
				<!--<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('本级排序号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="treeSort" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>-->
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:hidden path="isNewRecord"/>
							<#form:input path="customerId" maxlength="64" readonly="true" placeholder="自动生成" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('客户名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerName" id="customerName" maxlength="200" class="form-control required"/>
							</div>
						</div>
					</div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4">${text('上级客户')}：</label>
                            <div class="col-sm-8">
                                <#form:treeselect id="parent" title="${text('上级客户')}"
                                path="parent.customerId" labelPath="parent.customerName"
                                url="${ctx}/base/customer/customer/treeData?excludeCode=${customer.id}"
                                class="" allowClear="true" canSelectRoot="true" canSelectParent="true"/>
                            </div>
                        </div>
                    </div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('客户名称缩写')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:hidden name="oldCustomerNameAbbreviation" id="oldCustomerNameAbbreviation" value="${customer.customerNameAbbreviation}"/>
                                <#form:input path="customerNameAbbreviation" id="customerNameAbbreviation" maxlength="4"  minlength="4"
                                class="form-control required"
                                remote="${ctx}/base/customer/customer/checkAbbreviation?oldCustomerNameAbbreviation=${customer.customerNameAbbreviation}"
                                data-msg-remote="${text('客户名称缩写已存在')}"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('档案状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="status" dictType="sys_search_status" readonly="true"  class="form-control required" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('默认担保人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="guarantorId" items="${listGuar}"
                                itemLabel="guarantorName" itemValue="guarantorId" blankOption="true"
                                class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('客户经理')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="accountManager" items="${listUser}"
                                itemLabel="userName" itemValue="userCode" blankOption="true" class="form-control required" />
							</div>
						</div>
					</div>
				</div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                <span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-10">
                                <#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-unit">${text('法人、经办人信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('法人姓名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="corporateName" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('法人身份证')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="corporateIdcard" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('经办人姓名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="transactorName" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('经办人身份证')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="transactorIdcard" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('地址信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('国家/省份/城市')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="area" title="${text('选择')}"
									path="area.areaCode" labelPath="area.areaName" labelValue="${customer.area.treeNames!}"
									url="${ctx}/sys/area/treeData" returnFullName="true"
									class="" allowClear="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('详细地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="address" maxlength="200" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('工商、账户信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('纳税人识别号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="taxpayerIdentificationNumber" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('户名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="accountName" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('账号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="accountNumber" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('银行名称及地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="bankNameAddress" maxlength="200" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
                <!--<div class="form-unit">${text('展厅信息')}</div>
				<div class="ml10 mr10">
					<table id="customerShowroomDataGrid"></table>
					<% if (hasPermi('base:customer:customer:edit')){ %>
						<a href="#" id="customerShowroomDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
				</div>-->
                <div class="form-unit">${text('联系人列表')}</div>
				<div class="ml10 mr10">
					<table id="customerContactDataGrid"></table>
					<% if (hasPermi('base:customer:customer:edit')){ %>
						<a href="#" id="customerContactDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
				</div>
                <div class="form-unit">${text('准入资料明细以及附件')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('资料更新日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="dataUpdateDate" readonly="true" maxlength="20" class="form-control laydate required"
                                dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('更新周期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateCycle" class="form-control required number"/>
                            </div>
                        </div>
                    </div>
                </div>
				<div class="ml10 mr10">
					<table id="customerDataDataGrid"></table>
					<% if (hasPermi('base:customer:customer:edit')){ %>
						<a href="#" id="customerDataDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
				</div>
			</div>
            <div class="form-unit">${text('系统信息')}</div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="createDate" class="form-control" disabled="true"
                            dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <!--<#form:input path="createBy" class="form-control" disabled="true"/>-->
                            <#form:select path="createBy" items="${listUser}" disabled="true"
                            itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
                            dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <!--<#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>-->
                            <#form:select path="updateBy" items="${listUser}" disabled="true"
                            itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('base:customer:customer:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化展厅DataGrid对象
/*$("#customerShowroomDataGrid").dataGrid({

	data: ${toJson(customer.customerShowroomList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'showroomId', editable:true, hidden:true},
		{header:'${text("展厅名称")}', name:'showroomName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
        {header:'${text("展厅类型")}', name:'showroomType', width:100,
            editable:true, edittype:'select', editoptions:{'class':'form-control',
                items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('erp_showroomtype')}),
                itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
                    $(element).select2().on("change",function(){$(this).resetValid()});
                }
            }
        },
        {header:'${text("面积")}', name:'acreage', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("备注")}', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'500', 'class':'form-control', 'rows':'1'}},
		{header:'${text("客户ID")}', name:'customerId.customerId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', align:"center", width:50, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			if (val == 'new'){
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#customerShowroomDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}else{
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#customerShowroomDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#customerShowroomDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {showroomId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'customerShowroomList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,showroomId,showroomName,showroomType,acreage,remarks,customerId.customerId', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});*/
//初始化联系人DataGrid对象
$("#customerContactDataGrid").dataGrid({
	data: ${toJson(customer.customerContactList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'contactId', editable:true, hidden:true},
		{header:'${text("姓名")}', name:'contactName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("职务")}', name:'position', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("联系电话")}', name:'phone', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("邮箱")}', name:'email', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("联系人地址")}', name:'contactPersonAddr', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
        /*{dictLabel:'&nbsp;',dictValue:''}*/
        {header:'${text("是否主要联系人")}', name:'mainFlag', width:150,
			editable:true, edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([], ${@DictUtils.getDictListJson('sys_yes_no')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("客户ID")}', name:'customerId.customerId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', align:"center", width:50, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			if (val == 'new'){
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#customerContactDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}else{
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#customerContactDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],

	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#customerContactDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {contactId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'customerContactList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,contactId,contactName,position,phone,email,contactPersonAddr,mainFlag,customerId.customerId', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
//初始化客户资料DataGrid对象 准入资料明细以及附件
$("#customerDataDataGrid").dataGrid({
	data: ${toJson(customer.customerDataList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'dataId', editable:true, hidden:true},
		{header:'${text("客户ID")}', name:'customerId.customerId', editable:true, hidden:true},
        // {header:'${text("名称")}', name:'dataName', editable:true, hidden:true},
		// {header:'${text("名称")}', name:'dataName', width:80, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
        {header:'${text("名称")}', name:'dataName', width:80,
            editable:true, edittype:'select', editoptions:{'class':'form-control required',
                items: ${toJson(listDataConfig)},
                itemLabel: 'dataconName', itemValue: 'dataconId',
                dataInit: function(element){
                    $(element).select2().on("change",function(){
                        $(this).resetValid();
                        var dataconRequire = "0";
                        $.ajax({
                            type: "POST",
                            async : false,
                            url: "${ctx}/base/customerdataconfig/customerDataconfig/getOneById",
                            data: {"dataconId": $(this).val()},
                            success: function (result) {
                                dataconRequire = result.dataconRequire;
                            }
                        });
                        $(this).closest('tr').find('[aria-describedby="customerDataDataGrid_required"] .editable').val(dataconRequire).trigger('change');
                        if (dataconRequire =="1"){
                            $(this).closest('tr').find('[aria-describedby="customerDataDataGrid_requiredText"]').html("是").trigger('change');
                        }else {
                            $(this).closest('tr').find('[aria-describedby="customerDataDataGrid_requiredText"]').html("否").trigger('change');
                        }

                    });
                }
            }
        },


        {header:'${text("是否必填")}', name:'requiredText', index:'a.required', width:40, align:"center"},
        {header:'${text("是否必填")}', name:'required', width:100,hidden:true,
            editable:true, edittype:'select', editoptions:{'class':'form-control',
                items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('sys_yes_no')}),
                itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
                    $(element).select2().on("change",function(){$(this).resetValid()});
                }
            }
        },

        {header:'${text("文件上传")}', name:'id', align:"center", width:200,
            editable: true, edittype: "custom", editoptions: {
                custom_element: function(val, editOptions) {
                    return js.template('fileuploadTpl', {
                        id: 'fileupload_'+editOptions.id, title: '区域选择',
                        bizKey: val, bizType: 'customerData_file', cssClass: ''
                    });
                }
            }
        },
        {header:'${text("操作")}', name:'actions', align:"center", width:50, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			if (val == 'new'){
			    // if (!obj.irow)
                actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#customerDataDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}else{
                actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#customerDataDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#customerDataDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {dataId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'customerDataList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,dataId,dataName,required,customerId.customerId,customerData_file,customerData_file__del', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
     /* $("#customerDataDataGrid").jqGrid("addRow", {
            position: "1",
            addRowParams: {keys: false, focusField: true},
            initdata: {id: "", status: Global.STATUS_NORMAL,dataName:"营业执照复印件加盖公章", required: 1}
        });*/
	}
});

</script>
<script>
    $("#inputForm").validate({
        submitHandler: function(form){

            /*var checkCon = false;
            var listDataIDS = $('#customerContactDataGrid').dataGrid('getDataIDs');
            for (var i = 0; i < listDataIDS.length; i++) {
                var rowID = listDataIDS[i];
                $('#customerContactDataGrid').dataGrid('saveRow', rowID, true);
                $("#customerContactDataGrid").dataGrid("restoreRow", rowID);
                var rowData = $("#customerContactDataGrid").dataGrid("getRowData", rowID);
                // log("rowData=" + JSON.stringify(rowData));
                // log("rowData.mainFlag=" + rowData.mainFlag);
                if (rowData.mainFlag == '是'){
                    checkCon = true;
                }
                $("#customerContactDataGrid").dataGrid("editRow", rowID, {keys: true, focusField: true});
            }
            if(checkCon){*/

                js.ajaxSubmitForm($(form), function(data){
                    js.showMessage(data.message);
                    if(data.result == Global.TRUE){
                        js.closeCurrentTabPage(function(contentWindow){
                            contentWindow.$('#dataGrid').dataGrid('refreshTreeChildren',
                                $('#parentCode').val(), '${customer.id}');
                        });
                    }
                }, "json");
           /* }else{
                js.alert("联系人至少一个主要联系人");
                return;
            }*/

        }
    });

// 选择上级节点回调方法
function treeselectCallback(id, act, index, layero){
if (id == 'parent' && (act == 'ok' || act == 'clear')){
    // 创建并初始化下一个节点信息，如：排序号、默认值
    $.get('${ctx}/base/customer/customer/createNextNode?parentCode='
            +$('#parentCode').val(), function(data){
        $('#treeSort').val(data.treeSort);
    });
}
}


</script>


<script id="fileuploadTpl" type="text/template">//<!--<div>
<#form:fileupload id="{{d.id}}" bizKey="{{d.bizKey}}" bizType="{{d.bizType}}"
	uploadType="all" class="{{d.cssClass}}" isMini="true" preview="true"/>
</div>//--></script>


<script>
    // 获取客户名称的拼音字母
    $("#customerName").change(function () {
        var chinaName = $(this).val();
        var easyName = pinyin.getCamelChars(chinaName).substring(0,4);
        $("#customerNameAbbreviation").val(easyName);
        var oldCustomerNameAbbreviation = $("#oldCustomerNameAbbreviation").val();
        var url = "${ctx}/base/customer/customer/checkAbbreviation?oldCustomerNameAbbreviation="+oldCustomerNameAbbreviation+"&customerNameAbbreviation="+easyName;
        $.post(url,null,function (result) {
            if (result == 'false'){
                js.showMessage("客户名称缩写已存在！");
            }
        });
    });

</script>
